package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.SystemPost;
import com.atguigu.lease.model.entity.SystemUser;
import com.atguigu.lease.web.admin.mapper.SystemPostMapper;
import com.atguigu.lease.web.admin.mapper.SystemUserMapper;
import com.atguigu.lease.web.admin.service.SystemUserService;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserItemVo;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserQueryVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * @author liubo
 * @description 针对表【system_user(员工信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser>
        implements SystemUserService {
    @Resource
    private SystemUserMapper systemUserMapper;
    @Resource
    private SystemPostMapper systemPostMapper;

    //根据条件 分页查询用户信息
    @Override
    public IPage<SystemUserItemVo> pageSystemUserItemVo(Page<SystemUser> systemUserItemVoPage, SystemUserQueryVo queryVo) {
        return systemUserMapper.pageSystemUserItemVo(systemUserItemVoPage,queryVo);
    }

    //根据id查询后台用户信息
    @Override
    public SystemUserItemVo getByIdSystemUserItemVo(Long id) {
        //1.查询用户信息表得到 岗位id 根据岗位id查询相应的岗位 并进行结果组装
        SystemUser systemUser = systemUserMapper.selectById(id);
        //2.根据id查询相应的岗位信息
        SystemPost systemPost = systemPostMapper.selectById(systemUser.getPostId());
        //3.结果组装
        SystemUserItemVo systemUserItemVo = new SystemUserItemVo();
        BeanUtils.copyProperties(systemUser,systemUserItemVo);
        systemUserItemVo.setPostName(systemPost.getName());
        return systemUserItemVo;


    }
}




